﻿/* 'app' MODULE DEFINITION */
var appModule = angular.module("app", [
    "ui.router",
    "ui.bootstrap",
    'ui.utils',
    "ui.jq",
    'ui.grid',
    'ui.grid.pagination',
    "oc.lazyLoad",
    "ngSanitize",
    'angularFileUpload',
    'daterangepicker',
    'angularMoment',
    'frapontillo.bootstrap-switch',
    'abp',
    'textAngular',
    "com.2fdevs.videogular",
    "com.2fdevs.videogular.plugins.controls",
    "com.2fdevs.videogular.plugins.overlayplay",
    "com.2fdevs.videogular.plugins.poster",
    'ng.ueditor',
    'localytics.directives',
]).config(['chosenProvider', function (chosenProvider) {
    chosenProvider.setOption({
        no_results_text: '没有相关结果!',
        placeholder_text_multiple: '请选择!',
        placeholder_text_single:'请选择一项'
    });
}]);

/* LAZY LOAD CONFIG */

/* This application does not define any lazy-load yet but you can use $ocLazyLoad to define and lazy-load js/css files.
 * This code configures $ocLazyLoad plug-in for this application.
 * See it's documents for more information: https://github.com/ocombe/ocLazyLoad
 */
appModule.config(['$ocLazyLoadProvider', function ($ocLazyLoadProvider) {
    $ocLazyLoadProvider.config({
        cssFilesInsertBefore: 'ng_load_plugins_before', // load the css files before a LINK element with this ID.
        debug: false,
        events: true,
        modules: []
    });
}]);

/* THEME SETTINGS */
App.setAssetsPath(abp.appPath + 'metronic/assets/');
appModule.factory('settings', ['$rootScope', function ($rootScope) {
    var settings = {
        layout: {
            pageSidebarClosed: false, // sidebar menu state
            pageContentWhite: true, // set page content layout
            pageBodySolid: false, // solid body color state
            pageAutoScrollOnLoad: 1000 // auto scroll to top on page load
        },
        layoutImgPath: App.getAssetsPath() + 'admin/layout4/img/',
        layoutCssPath: App.getAssetsPath() + 'admin/layout4/css/',
        assetsPath: abp.appPath + 'metronic/assets',
        globalPath: abp.appPath + 'metronic/assets/global',
        layoutPath: abp.appPath + 'metronic/assets/layouts/layout4'
    };

    $rootScope.settings = settings;

    return settings;
}]);

/* ROUTE DEFINITIONS */

appModule.config([
    '$stateProvider', '$urlRouterProvider', '$qProvider',
    function ($stateProvider, $urlRouterProvider, $qProvider) {

        // Default route (overrided below if user has permission)
        $urlRouterProvider.otherwise("/welcome");

        //Welcome page
        $stateProvider.state('welcome', {
            url: '/welcome',
            templateUrl: '~/App/common/views/welcome/index.cshtml'
        });

        //COMMON routes
        //----------------------------------------------------------------------------------------------------------------
        if (abp.auth.hasPermission('Pages.BasicPerson')) {
            $stateProvider.state('basicPersons', {
                url: '/basicPersons?filterText',
                templateUrl: '~/App/common/views/basicPersons/index.cshtml',
            });
        }

        //if (abp.auth.hasPermission('Pages.SpecialPerson')) {
        //    $stateProvider.state('specialPersons', {
        //        url: '/specialPersons?filterText',
        //        templateUrl: '~/App/common/views/specialPersons/index.cshtml',
        //    });
        //}

        //涉军类
        if (abp.auth.hasPermission('Pages.SpecialPerson')) {
            $stateProvider.state('sheJun', {
                url: '/specialPersons?filterText',
                templateUrl: '~/App/common/views/specialPersons/index.cshtml',
                params: { 'personTypeID': 1 },
            });
        }

        //涉教类
        if (abp.auth.hasPermission('Pages.SpecialPerson')) {
            $stateProvider.state('sheJiao', {
                url: '/specialPersons?filterText',
                templateUrl: '~/App/common/views/specialPersons/index.cshtml',
                params: { 'personTypeID': 2 },
            });
        }

        //原计划生育临时工
        if (abp.auth.hasPermission('Pages.SpecialPerson')) {
            $stateProvider.state('shengYuLinShiGong', {
                url: '/specialPersons?filterText',
                templateUrl: '~/App/common/views/specialPersons/index.cshtml',
                params: { 'personTypeID': 3 },
            });
        }

        //刑满释放人员
        if (abp.auth.hasPermission('Pages.SpecialPerson')) {
            $stateProvider.state('xingManShiFang', {
                url: '/specialPersons?filterText',
                templateUrl: '~/App/common/views/specialPersons/index.cshtml',
                params: { 'personTypeID': 4 },
            });
        }

        //违法青少年
        if (abp.auth.hasPermission('Pages.SpecialPerson')) {
            $stateProvider.state('weiFaQingShaoNian', {
                url: '/specialPersons?filterText',
                templateUrl: '~/App/common/views/specialPersons/index.cshtml',
                params: { 'personTypeID': 5 },
            });
        }

        //上访老人
        if (abp.auth.hasPermission('Pages.SpecialPerson')) {
            $stateProvider.state('shangFangLaoRen', {
                url: '/specialPersons?filterText',
                templateUrl: '~/App/common/views/specialPersons/index.cshtml',
                params: { 'personTypeID': 6 },
            });
        }

        //吸毒人员
        if (abp.auth.hasPermission('Pages.SpecialPerson')) {
            $stateProvider.state('xiDuRenYuan', {
                url: '/specialPersons?filterText',
                templateUrl: '~/App/common/views/specialPersons/index.cshtml',
                params: { 'personTypeID': 7 },
            });
        }

        //肇事肇祸精神病人
        if (abp.auth.hasPermission('Pages.SpecialPerson')) {
            $stateProvider.state('zhaoShiZhaoHuo', {
                url: '/specialPersons?filterText',
                templateUrl: '~/App/common/views/specialPersons/index.cshtml',
                params: { 'personTypeID': 8 },
            });
        }

        //社区矫正对象
        if (abp.auth.hasPermission('Pages.SpecialPerson')) {
            $stateProvider.state('sheQuJiaoZheng', {
                url: '/specialPersons?filterText',
                templateUrl: '~/App/common/views/specialPersons/index.cshtml',
                params: { 'personTypeID': 9 },
            });
        }

        //法轮功等邪教人员
        if (abp.auth.hasPermission('Pages.SpecialPerson')) {
            $stateProvider.state('faLunGong', {
                url: '/specialPersons?filterText',
                templateUrl: '~/App/common/views/specialPersons/index.cshtml',
                params: { 'personTypeID': 10 },
            });
        }

        //低保
        if (abp.auth.hasPermission('Pages.SpecialPerson')) {
            $stateProvider.state('diBao', {
                url: '/specialPersons?filterText',
                templateUrl: '~/App/common/views/specialPersons/index.cshtml',
                params: { 'personTypeID': 11 },
            });
        }

        if (abp.auth.hasPermission('Pages.PersonType')) {
            $stateProvider.state('personTypes', {
                url: '/personTypes?filterText',
                templateUrl: '~/App/common/views/personTypes/index.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.Area')) {
            $stateProvider.state('areas', {
                url: '/areas?filterText',
                templateUrl: '~/App/common/views/areas/index.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.Area')) {
            $stateProvider.state('areas_upPicture', {
                url: '/areas_upPicture?filterText',
                templateUrl: '~/App/common/views/areas/upPicture.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.Area')) {
            $stateProvider.state('areasList', {
                url: '/areasList?filterText',
                templateUrl: '~/App/common/views/areas/indexList.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.GridPerson')) {
            $stateProvider.state('gridPersons', {
                url: '/gridPersons?filterText',
                templateUrl: '~/App/common/views/gridPersons/index.cshtml',
            });
        }



        if (abp.auth.hasPermission('Pages.DisputeInformation')) {
            $stateProvider.state('disputeInformations', {
                url: '/disputeInformations?filterText',
                templateUrl: '~/App/common/views/disputeInformations/index.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.DisputeInformationHandle')) {
            $stateProvider.state('maoDunJiuFen', {
                url: '/maoDunJiuFen?filterText',
                templateUrl: '~/App/common/views/disputeInformations/maoDunJiuFen.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.DiaoChaDiaoChu')) {
            $stateProvider.state('diaoChaDiaoChu', {
                url: '/diaoChaDiaoChu?filterText',
                templateUrl: '~/App/common/views/disputeInformations/diaoChaDiaoChu.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.Agreement')) {
            $stateProvider.state('xieYiShu', {
                url: '/xieYiShu?filterText',
                templateUrl: '~/App/common/views/disputeInformations/xieYiShu.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.PerformanceAgreement')) {
            $stateProvider.state('lvXingXieYi', {
                url: '/lvXingXieYi?filterText',
                templateUrl: '~/App/common/views/disputeInformations/lvXingXieYi.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.DisputeInformationJieAnGuiDang')) {
            $stateProvider.state('jieAnGuiDang', {
                url: '/jieAnGuiDang?filterText',
                templateUrl: '~/App/common/views/disputeInformations/jieAnGuiDang.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.OtherChannels')) {
            $stateProvider.state('qiTaQuDao', {
                url: '/qiTaQuDao?filterText',
                templateUrl: '~/App/common/views/disputeInformations/qiTaQuDao.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.FenXiYanPan')) {
            $stateProvider.state('fenXiYanPan', {
                url: '/fenXiYanPan?filterText',
                templateUrl: '~/App/common/views/disputeInformations/fenXiYanPan.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.DisputeInformation')) {
            $stateProvider.state('barChart', {
                url: '/barChart?filterText',
                templateUrl: '~/App/common/views/disputeInformations/barChart.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.DisputeInformation')) {
            $stateProvider.state('pie', {
                url: '/pie?filterText',
                templateUrl: '~/App/common/views/disputeInformations/pie.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.DisputeInformation')) {
            $stateProvider.state('townbarChart', {
                url: '/townbarChart?filterText',
                templateUrl: '~/App/common/views/disputeInformations/townbarChart.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.DisputeInformation')) {
            $stateProvider.state('compareStatistics', {
                url: '/compareStatistics?filterText',
                templateUrl: '~/App/common/views/disputeInformations/compareStatistics.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.GenZongDuBan')) {
            $stateProvider.state('genZongDuBan', {
                url: '/genZongDuBan?filterText',
                templateUrl: '~/App/common/views/disputeInformations/genZongDuBan.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.DisputeInformation')) {
            $stateProvider.state('shiPinJieFang', {
                url: '/disputeInformations?filterText',
                templateUrl: '~/App/common/views/disputeInformations/index.cshtml',
            });
        }




        if (abp.auth.hasPermission('Pages.DisputeType')) {
            $stateProvider.state('disputeTypes', {
                url: '/disputeTypes?filterText',
                templateUrl: '~/App/common/views/disputeTypes/index.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.CaseCategory')) {
            $stateProvider.state('caseCategorys', {
                url: '/caseCategorys?filterText',
                templateUrl: '~/App/common/views/caseCategorys/index.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.WorkFlow')) {
            $stateProvider.state('workFlows', {
                url: '/workFlows?filterText',
                templateUrl: '~/App/common/views/workFlows/index.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.WorkFlow_Process')) {
            $stateProvider.state('workFlow_Processs', {
                url: '/workFlow_Processs?filterText',
                templateUrl: '~/App/common/views/workFlow_Processs/index.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.WorkFlow_Run')) {
            $stateProvider.state('workFlow_Runs', {
                url: '/workFlow_Runs?filterText',
                templateUrl: '~/App/common/views/workFlow_Runs/index.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.WorkFlow_Run_Process')) {
            $stateProvider.state('workFlow_Run_Processs', {
                url: '/workFlow_Run_Processs?filterText',
                templateUrl: '~/App/common/views/workFlow_Run_Processs/index.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.SupportingSystem')) {
            $stateProvider.state('supportingSystems', {
                url: '/supportingSystems?filterText',
                templateUrl: '~/App/common/views/supportingSystems/index.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.AssessmentReport')) {
            $stateProvider.state('assessmentReports', {
                url: '/assessmentReports?filterText',
                templateUrl: '~/App/common/views/assessmentReports/index.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.ProjectStatus')) {
            $stateProvider.state('projectStatuss', {
                url: '/projectStatuss?filterText',
                templateUrl: '~/App/common/views/projectStatuss/index.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.File')) {
            $stateProvider.state('files', {
                url: '/files?filterText',
                templateUrl: '~/App/common/views/files/index.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.WorkFlow_TableName')) {
            $stateProvider.state('workFlow_TableNames', {
                url: '/workFlow_TableNames?filterText',
                templateUrl: '~/App/common/views/workFlow_TableNames/index.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.CallPolice')) {
            $stateProvider.state('callPolices', {
                url: '/callPolices?filterText',
                templateUrl: '~/App/common/views/callPolices/index.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.CallPolice')) {
            $stateProvider.state('callPoliceAcceptance', {
                url: '/callPoliceAcceptance?filterText',
                templateUrl: '~/App/common/views/callPolices/callPoliceAcceptance.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.CallPolice')) {
            $stateProvider.state('callJieAnGuiDang', {
                url: '/callJieAnGuiDang?filterText',
                templateUrl: '~/App/common/views/callPolices/callJieAnGuiDang.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.CallPolice')) {
            $stateProvider.state('shiPinJianKong', {
                url: '/shiPinJianKong?filterText',
                templateUrl: '~/App/common/views/callPolices/shiPinJianKong.cshtml',
            });
        }

        //视频播放
        if (abp.auth.hasPermission('Pages.CallPolice')) {
            $stateProvider.state('video', {
                url: '/video?filterText',
                templateUrl: '~/App/common/views/callPolices/video.cshtml',
            });
        }

        if (abp.auth.hasPermission('Pages.CallType')) {
            $stateProvider.state('callTypes', {
                url: '/callTypes?filterText',
                templateUrl: '~/App/common/views/callTypes/index.cshtml',
            });
        }

        //法律法规
        if (abp.auth.hasPermission('Pages.LawsRegulations')) {
            $stateProvider.state('lawsRegulationss', {
                url: '/lawsRegulationss?filterText',
                templateUrl: '~/App/common/views/lawsRegulationses/index.cshtml',
            });
        }

        //消息通知
        if (abp.auth.hasPermission('Pages.Notification')) {
            $stateProvider.state('notificationManage', {
                url: '/notificationManage?filterText',
                templateUrl: '~/App/common/views/notificationManage/index.cshtml',
            });
        }

        //文章分类
        if (abp.auth.hasPermission('Pages.ArticleCategory')) {
            $stateProvider.state('articleCategorys', {
                url: '/articleCategorys?filterText',
                templateUrl: '~/App/common/views/articleCategorys/index.cshtml',
            });
        }

        //文章
        if (abp.auth.hasPermission('Pages.Article')) {
            $stateProvider.state('articles', {
                url: '/articles?filterText',
                templateUrl: '~/App/common/views/articles/index.cshtml',
            });
        }

        //APP版本号
        if (abp.auth.hasPermission('Pages.VersionApp')) {
            $stateProvider.state('versionApps', {
                url: '/versionApps?filterText',
                templateUrl: '~/App/common/views/versionApps/index.cshtml',
            });
        }

        //指挥调度
        if (abp.auth.hasPermission('Pages.CommandDispatch')) {
            $stateProvider.state('commandDispatches', {
                url: '/commandDispatches?filterText',
                templateUrl: '~/App/common/views/commandDispatches/index.cshtml',
            });
        }

        //视频接访
        if (abp.auth.hasPermission('Pages.VideoReceivers')) {
            $stateProvider.state('videoReceiverses', {
                url: '/videoReceiverses?filterText',
                templateUrl: '~/App/common/views/videoReceiverses/index.cshtml',
            });
        }

        //视频管理
        if (abp.auth.hasPermission('Pages.CameraManage')) {
            $stateProvider.state('cameraManages', {
                url: '/cameraManages?filterText',
                templateUrl: '~/App/common/views/cameraManages/index.cshtml',
            });
        }

        //视频会议
        if (abp.auth.hasPermission('Pages.UserMeetingRef')) {
            $stateProvider.state('userMeetingRefs', {
                url: '/userMeetingRefs?filterText',
                templateUrl: '~/App/common/views/userMeetingRefs/index.cshtml',
            });
        }

        //消防工作
        if (abp.auth.hasPermission('Pages.FireFightingWork')) {
            $stateProvider.state('fireFightingWorks', {
                url: '/fireFightingWorks?filterText',
                templateUrl: '~/App/common/views/fireFightingWorks/index.cshtml',
            });
        }

        //----------------------------------------------------------------------------------------------------------------
        if (abp.auth.hasPermission('Pages.Administration.Roles')) {
            $stateProvider.state('roles', {
                url: '/roles',
                templateUrl: '~/App/common/views/roles/index.cshtml'
            });
        }

        if (abp.auth.hasPermission('Pages.GridPerson.Users')) {
            $stateProvider.state('users', {
                url: '/users?filterText',
                templateUrl: '~/App/common/views/users/index.cshtml'
            });
        }

        if (abp.auth.hasPermission('Pages.RegisterPerson.Users')) {
            $stateProvider.state('masses', {
                url: '/masses?filterText',
                templateUrl: '~/App/common/views/users/masses.cshtml'
            });
        }

        if (abp.auth.hasPermission('Pages.Administration.Languages')) {
            $stateProvider.state('languages', {
                url: '/languages',
                templateUrl: '~/App/common/views/languages/index.cshtml'
            });

            if (abp.auth.hasPermission('Pages.Administration.Languages.ChangeTexts')) {
                $stateProvider.state('languageTexts', {
                    url: '/languages/texts/:languageName?sourceName&baseLanguageName&targetValueFilter&filterText',
                    templateUrl: '~/App/common/views/languages/texts.cshtml'
                });
            }
        }

        if (abp.auth.hasPermission('Pages.Administration.AuditLogs')) {
            $stateProvider.state('auditLogs', {
                url: '/auditLogs',
                templateUrl: '~/App/common/views/auditLogs/index.cshtml'
            });
        }

        if (abp.auth.hasPermission('Pages.Administration.OrganizationUnits')) {
            $stateProvider.state('organizationUnits', {
                url: '/organizationUnits',
                templateUrl: '~/App/common/views/organizationUnits/index.cshtml'
            });
        }

        $stateProvider.state('notifications', {
            url: '/notifications',
            templateUrl: '~/App/common/views/notifications/index.cshtml'
        });

        //HOST routes

        $stateProvider.state('host', {
            'abstract': true,
            url: '/host',
            template: '<div ui-view class="fade-in-up"></div>'
        });

        if (abp.auth.hasPermission('Pages.Tenants')) {
            $urlRouterProvider.otherwise("/host/tenants"); //Entrance page for the host
            $stateProvider.state('host.tenants', {
                url: '/tenants?filterText',
                templateUrl: '~/App/host/views/tenants/index.cshtml'
            });
        }

        if (abp.auth.hasPermission('Pages.Editions')) {
            $stateProvider.state('host.editions', {
                url: '/editions',
                templateUrl: '~/App/host/views/editions/index.cshtml'
            });
        }

        if (abp.auth.hasPermission('Pages.Administration.Host.Maintenance')) {
            $stateProvider.state('host.maintenance', {
                url: '/maintenance',
                templateUrl: '~/App/host/views/maintenance/index.cshtml'
            });
        }

        if (abp.auth.hasPermission('Pages.Administration.Host.Settings')) {
            $stateProvider.state('host.settings', {
                url: '/settings',
                templateUrl: '~/App/host/views/settings/index.cshtml'
            });
        }

        //TENANT routes

        $stateProvider.state('tenant', {
            'abstract': true,
            url: '/tenant',
            template: '<div ui-view class="fade-in-up"></div>'
        });

        if (abp.auth.hasPermission('Pages.Tenant.Dashboard')) {
            $urlRouterProvider.otherwise("/tenant/dashboard"); //Entrance page for a tenant 
            $stateProvider.state('tenant.dashboard', {
                url: '/dashboard',
                templateUrl: '~/App/tenant/views/dashboard/index.cshtml'
            });
        }

        if (abp.auth.hasPermission('Pages.Administration.Tenant.Settings')) {
            $stateProvider.state('tenant.settings', {
                url: '/settings',
                templateUrl: '~/App/tenant/views/settings/index.cshtml'
            });
        }

        //$qProvider settings
        $qProvider.errorOnUnhandledRejections(false);
    }
]);

appModule.run(["$rootScope", "settings", "$state", 'i18nService', '$uibModalStack', function ($rootScope, settings, $state, i18nService, $uibModalStack) {
    $rootScope.$state = $state;
    $rootScope.$settings = settings;

    $rootScope.$on('$stateChangeSuccess', function () {
        $uibModalStack.dismissAll();
    });

    //Set Ui-Grid language
    if (i18nService.get(abp.localization.currentCulture.name)) {
        i18nService.setCurrentLang(abp.localization.currentCulture.name);
    } else {
        i18nService.setCurrentLang("en");
    }

    $rootScope.safeApply = function (fn) {
        var phase = this.$root.$$phase;
        if (phase == '$apply' || phase == '$digest') {
            if (fn && (typeof (fn) === 'function')) {
                fn();
            }
        } else {
            this.$apply(fn);
        }
    };
}]);